<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="uc-nav">
    <ul  id="content_grid">
        <li class="active"><a href="javascript:;">全部</a></li>
        <li status="2,3,9,13"><a href="javascript:;">已受理</a></li>
        <li status="0,1"><a href="javascript:;">未受理</a></li>
        <li status="-1"><a href="javascript:;">已撤销</a></li>
    </ul>
</div>
<div  >
    <div id="content_appointments" class="ucr-centent">
    </div>
    <div style="text-align: center;">
    <div id="page" class="pagination"></div>
    </div>
</div>
<!-- 模板-->
<script id="temp_appointments" type="text/html">
    <table class="table table-border">
        <colgroup>
            <col width="20%">
            <col width="20%">
            <col width="20%">
            <col width="20%">
            <col width="20%">
        </colgroup>
        <thead>
        <tr>
            <th>预约编号</th>
            <th>预约名称</th>
            <th>预约时间</th>
            <th>预约状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {{if list.length==0}}
        <tr>
            <td colspan="5">暂未找到您的数据</td>
        </tr>
        {{/if}}
        {{each list as value i}}
        <tr>
            <td>{{value.tskNum}}</td>
            <td>{{value.matName}}</td>
            <td>{{value.startdodate}}</td>
            <td>{{value.projectstatusCn}}</td>
            <td>
                <a href="javascript:;" class="btn btn-xs btn-blue" onclick="showDetail('{{value.tskNum}}')">查看</a>
                <a href="javascript:;" class="btn btn-xs btn-danger" onclick="deleteTask('{{value.guid}}')">删除</a>
            </td>
        </tr>
        {{/each}}
        </tbody>
    </table>

</script>
<script id="temp_detail" type="text/html">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">
            <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
        </button>
        <h2 class="thing-h">{{matName}}</h2>
    </div>
    <div class="modal-body">
        <div class="thing-item">
            <div class="thing-item-title">预约信息</div>
            <div class="thing-item-bd">
                <table class="table table-bordered">
                    <tr>
                        <th>预约编号：</th>
                        <td>{{tskNum}}</td>
                        <th>数据来源：</th>
                        <td>
                            {{if tskSouce=='SYS'}}
                            本系统
                            {{else if tskSouce=='INT'}}
                            地市上报
                            {{else}}
                            其它
                            {{/if}}
                        </td>
                    </tr>
                    <tr>
                        <th>预约方式：</th>
                        <td>
                            {{if netprojecttype=='WIN'}}
                            窗口办件
                            {{else if netprojecttype=='PCP'}}
                            大厅申报
                            {{else if netprojecttype=='WEI'}}
                            微信申报
                            {{else if netprojecttype=='WAP'}}
                            wap申报
                            {{else if netprojecttype=='APP'}}
                            移动端申报
                            {{/if}}
                        </td>
                        <th>预约状态：</th>
                        <td>{{projectstatusCn}}</td>
                    </tr>
                    <tr>
                        <th>预约时间：</th>
                        <td>{{startdodate}}</td>
                        <th>受理部门：</th>
                        <td>{{deptName}}</td>
                    </tr>
                    <tr>
                        <th>申报人：</th>
                        <td>{{unitname}}</td>
                        <th>申请人手机号：</th>
                        <td>{{handphone}}</td>
                    </tr>
                    <tr>
                        <th>身份证号码：</th>
                        <td>{{unitnumber.substring(0,6)}}***********{{unitnumber.substring(17)}}</td>
                        <th>地址：</th>
                        <td>{{unitaddress}}</td>
                    </tr>
                </table>
            </div>
        </div>
        {{if checkInfos.length>0}}
        <div class="thing-item">
            <div class="thing-item-title">审批意见</div>
            <div class="thing-item-bd">
                <table class="table table-bordered">
                    {{each checkInfos as value i}}
                    <tr>
                        <th width="15%">审批结果：</th>
                        <td width="35%">
                            {{ if checkresult=='OK'}}
                            同意
                            {{else}}
                            不同意
                            {{/if}}
                        </td>
                        <th width="15%">审批意见：</th>
                        <td width="35%">{{checkidea}}</td>
                    </tr>
                    {{/each}}
                </table>
            </div>
        </div>
        {{/if}}
    </div>
    <div class="modal-footer">
        <div class="btn-box">
            <a  class="btn btn-yellow btn-lg" href="javascript:;" onclick="cancleTask('{{guid}}')">撤销</a>
            <a  class="btn btn-yellow btn-lg" href="javascript:;" onclick="$('.detail-modal').modal('hide');">取消</a>
        </div>
    </div>
</script>
<div class="modal fade detail-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content"  id="content_detail">

        </div>
    </div>
</div>
<script>
    var page_index=1,page_size=10;
    $(function(){
        $(".uc-nav li").each(function(){
            $(this).click(function(){
                $(".active").removeClass("active");
                $(this).addClass("active");
                getList(page_index,page_size,$(this).attr("status"));
            })
        })
        getList(page_index,page_size);
//        $('.detail-modal').on('hide.bs.modal', function () {
////            clearSaForm();
//        })
    });
    function getList(pi,ps,status){
        $.ajax({
            url:"<c:url value='/usercenter/task-list'/>",
            type:"GET",
            data:{
                ps:ps,
                pi:pi,
                tsk_reserve:"Y",
                status:status
            },
            dataType:"json",
            success:function(res){
                if(res.succ){
                    var shtml = template("temp_appointments", res.data);
                    $("#content_appointments").html(shtml);
                    $("#page").jqPaginator({
                        totalPages: res.data.totalPage==0?1:res.data.totalPage,
                        visiblePages: 10,
                        currentPage: pi,
                        pageSize: ps,
                        onPageChange: function (n,type) {
                            if(type=='change'){
                                getList(n, ps,status);
                            }
                        }
                    });
                }else{toast(res.msg);}
            },
            error:function(res){toast(res.msg);}
        });
    }
    function showDetail(num) {
        $.ajax({
            type: "GET",
            url: "<c:url value='/taskbases/num'/>",
            data: {
                num:num
            },
            dataType: "json",
            success: function (resp) {
                if(resp.succ){
                    var shtml = template("temp_detail", resp.data);
                    $("#content_detail").html(shtml);
                    $('.detail-modal').modal();
                }else{
                    toast(resp.msg);
                }
            },
            error: function () {
                toast("服务器异常");
            }
        });

    }
    function cancleTask(guid) {
        $.ajax({
            type: "PATCH",
            url: "<c:url value='/usercenter/'/>"+guid,
            data: JSON.stringify({
                tskCancle:'Y',
                projectstatus:"-1",
                projectstatusCn:"已撤销"
            }),
            contentType: 'application/json;charset=utf-8',
            dataType: "json",
            success: function (resp) {
                if(resp.succ){
                    toast("撤销成功");
                    $('.detail-modal').modal("hide");
                    getList(page_index,page_size,$(".active").attr("status"));
                }else{
                    toast(resp.msg);
                }
            },
            error: function () {
                toast("服务器异常");
            }
        });
    }
    function deleteTask(guid){
        $.ajax({
            type: "PATCH",
            url: "<c:url value='/usercenter/'/>"+guid,
            data: JSON.stringify({
                deleted:'Y'
            }),
            contentType: 'application/json;charset=utf-8',
            dataType: "json",
            success: function (resp) {
                if(resp.succ){
                    toast("删除成功");
                    getList(page_index,page_size,$(".active").attr("status"));
                }else{
                    toast(resp.msg);
                }
            },
            error: function () {
                toast("服务器异常");
            }
        });
    }
</script>